

<template>
  <div class="checkTable">
    
      <mu-appbar color="primary" class="lan-header">
        <mu-button icon slot="left" @click="$emit('cancel')">
          <i class="iconfont angle-left iconangle-left"></i>
          <span class="lan-header-back">返回</span>
        </mu-button>检查表
        <mu-button icon slot="right" >
          <!-- <span class="text">清空</span> -->
        </mu-button>
      </mu-appbar>
      <mu-list class="lan-dialog-body no-padding">
       <mu-list-item button  v-for="(item,index) in allTableData" :key="index">
            <mu-checkbox class="list-checkbox" v-model="checkboxSelected" :value="item.id" :label="item.name"></mu-checkbox>
       </mu-list-item>
        
      </mu-list>
        <div class="lan-dialog-sumit list-save-btn lan-block-btn-line">
          <mu-button full-width color="primary" class="lan-block-btn"  @click="okSelect">确认</mu-button>
        </div>
  </div>
</template>

<script>

  export default {
    name: 'checkTable',
    components: {
     
    },
    props: {
      // 选择结果
      checkedList: {
        type: Array,
        default: () => []
      },
      cancel: {
        type: Function,
        default: () => []
      },
      ok: {
        type: Function,
        default: () => this.selected
      },
    },
    // model: {
    //   prop: "visible",
    //   event: "change"
    // },
    data() {
      return {
        selected:[],
        checkboxSelected:[],
        allTableData:[],
        jishu:0,
      }
    },
    computed: {},
    created() {
        this.getAllTable()
        if(this.checkedList.length>0){
            this.checkboxSelected = this.checkedList;
        }
    },
    mounted() {
    },
    watch: {},
    methods: {
      //获取质量检查表列表
        async getAllTable(){
            this.$openLoading();
            this.jishu = 1
            let obj = {
                "orgId":this.$A.GS('orgInfo')['orgId'],
                "type":this.$A.GS('orgInfo')['type'],
                "current":-1,
                "size":0,
                "status":'0',
            };
            this.$A.Go('get','/safety/checkTable/pageList',obj).then(async success=>{
                if(success.code == 200){
                     let data = success.body.rows;
                     for(let i=0 ; i<data.length;i++){
                         data[i]['detailInfo'] = await this.getDetail(data[i]['id'])
                     }

                     this.allTableData = data
                    //  this.$closeLoading(); 
                }else{
                    this.allTableData = [];
                    // this.$closeLoading();
                }
                this.$closeLoading();
            },function(err){
                console.log(err)
                this.$closeLoading();
            })
        },
        async getDetail(id){
            let obj = {id}
            return this.$A.Go('get','/safety/checkTable/detail',obj).then(success=>{
                this.jishu++
                if(this.jishu >= this.allTableData.length){
                  this.$closeLoading();
                }
                if(success.code == 200){
                return  success.body
                }else{
                return  null
                }
                
            },function(err){
                console.log(err)
                return null
            })
        },
        okSelect(){
            // console.log(this.checkboxSelected)
            let data = [];
            for(let i=0; i<this.allTableData.length; i++){
                if(this.checkboxSelected.includes(this.allTableData[i]['id'])){
                    data.push(this.allTableData[i])
                }
            }
            this.$emit('ok', data)
        },
    },
    destroyed() {
    }
  }
</script>

<style lang="scss" scoped>
.checkTable{
    width:100%;
    height:100%;
    display: flex;
    flex-direction: column;
}
</style>
